<template>
    <view class="content">
        <view class="main">
            <image src="@/static/images/index/settled_tip.png" mode="scaleToFill" class="login-bg" />
            <view class="login-title">欢迎您的加入</view>
        </view>
        <up-button type="primary" shape="circle" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" text="立即登录"
            block color="#F2CB51"></up-button>
    </view>
</template>
<script setup>
import { ref, getCurrentInstance } from 'vue'
const { proxy } = getCurrentInstance()

const phoneCode = ref('')
function login() {
    // const res = await this.$request('/account/get/user/info', {}, {
    // 				method: 'GET'
    // 			});
    // toPage('/pages/index/index')
}

function getPhoneNumber(e) {
    if (e.detail.errMsg == 'getPhoneNumber:ok') {
        phoneCode.value = e.detail.code
        wx.login({
            success: async ({ code }) => {
                let params = {
                    code: code,
                    phoneCode: phoneCode.value
                }
                console.log(params)
                const res = await proxy.request('/account/wx/login', params)
                const { flg, token } = res.data
                uni.setStorageSync('token', token)
                console.log(flg, token)
                toPage('/pages/index/index')

            }
        })
    }
}

function toPage(url) {
    uni.switchTab({ url })
}
</script>
<style lang="scss">
page {
    background-color: #FFFFFF;
    padding: 64rpx;
    box-sizing: border-box;
}

.main {
    margin-bottom: 88rpx;
    padding: 32rpx;
    text-align: center;

    .login-title {
        width: 100%;
        text-align: center;
        font-size: 32rpx;
        font-weight: bold;
    }

    .login-bg {
        width: 220rpx;
        height: 220rpx;
    }

}
</style>